package 十大排序算法;

public class 快速排序 {
    public void sort(int[] a,int low,int high){
        int start = low;
        int end = high;
        int key = a[low];
        while (start<end){
            if (end>start&&key<=a[end]){
                end--;
            }if (a[end]<key){
                int tmp = a[end];
                a[end] = a[start];
                a[start] = tmp;
            }

        }
        while (start<end){
            if (end>start&&key>=a[start]){
                start++;
            }if (key<a[start]){
                int tmp = a[start];
                a[start] = a[end];
                a[end] = tmp;
            }
        }
        //至此完成了一次排序 然后开始递归起来剩下的
        if (start>low) sort(a,low,start-1);
        if (end<high) sort(a,end+1,high);
     }
}
